/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: Payment.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/15 下午3:41
 * LastModified: 2020/03/15 15:41:15
 */

package com.qolome.knowledge.design.pattern.strategy.demo.pay;

import com.qolome.enums.ResultEnum;
import com.qolome.utils.web.HttpResult;

import java.math.BigDecimal;

import static com.qolome.utils.web.HttpResult.builder;

/**
 * @author Qolome
 * @version V1.0
 * @Description 支付
 * @date 2020年 03月15日 15:41:49
 */
public abstract class AbstractPayment {

    public abstract String getName();


    public  HttpResult<String> pay(String uid, BigDecimal amount){

        if (amount.compareTo(queryBalance(uid)) > 0){
            return HttpResult.<String>builder()
                    .message("余额不足")
                    .data("支付失败")
                    .code(200)
                    .build();
        }
        return HttpResult.success("支付成功",null);

    }

    protected abstract BigDecimal queryBalance(String uid);

}
